<template>
  <view class="container ver-layout-center">
    <input class="input-view" v-model="password1" password focus="true" maxlength="10" placeholder="输入新密码">
    <input class="input-view" v-model="password2" password maxlength="10" placeholder="再次输入新密码">
    <button class="update-btn" :disabled="!canSaveUse" @click="resetPwd">更新</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      password1: '',
      password2: ''
    }
  },
  computed: {
    canSaveUse() {
      if (this.password1 === this.password2 && this.password1 != "")
        return true
      return false
    }
  },
  onLoad(options) {
    console.log(options)
    let action = options.action
    uni.setNavigationBarTitle({
      title: action
    })
  },
  methods: {
    resetPwd() {
      let uid = uni.getStorageSync('uid')
      let token = uni.getStorageSync('token')
      uniCloud.callFunction({
        name: 'user-center',
        data: {
          action: 'resetPwd',
          uniIdToken: token,
          params: {
            password: this.password1,
            uid: uid
          }
        }
      }).then(res => {
        if (res.result.code === 0) {
          this.$tools.pageBackDelay("修改成功！")
          return
        }
        this.$tools.showToast("修改失败，请稍后再试！")
      }).catch(err => {
        this.$tools.showToast("修改失败，请稍后再试！")
      })
    },
  }
}
</script>

<style>
page {
  background: #eeeeee;
}

.input-view {
  margin-top: 12px;
  padding: 6px;
  background: white;
  border: 1px solid #8e929c;
  border-radius: 5px;
  position: relative;
  font-size: small;
  width: 50%;
}

.update-btn {
  margin-top: 15px;
  font-size: small;
  width: 20%;
}
</style>
